<div class="layui-card">
    <div class="layui-card-header">
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>充值管理</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            搜索：
            <select id="recharge-search-key">
                <option value="">-请选择-</option>
                <option value="player_id">ID</option>
            </select>
            <input id="recharge-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            <button id="recharge-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>
        <table class="layui-table" id="recharge-table" lay-filter="recharge-table"></table>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="recharge-table-bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="check">查看详情</a>
</script>

<script>
    layui.use(['table', 'util', 'config','index'], function () {
        var table = layui.table;
        var config = layui.config;
        var util = layui.util;
        var index = layui.index;


        // 渲染表格
        table.render({
            elem: '#recharge-table',
            url: config.base_server + 'api-select/recharge',
            method: 'GET',
            where: {
                access_token: config.getToken().access_token
            },
            page: true,
            cols: [[
                {type: 'numbers'},
                {field: 'id', sort: true, title: '用户编号'},
                {
                    field: 'firstChargeTime', sort: true, templet: function (d) {
                        return util.toDateString(d.firstChargeTime);
                    }, title: '首冲时间'
                },
                {
                    field: 'lastChargeTime', sort: true, templet: function (d) {
                        return util.toDateString(d.lastChargeTime);
                    }, title: '最近充值时间'
                },
                {field: 'dayCharge', sort: true, title: '今日充值'},
                {field: 'total', sort: true, title: '累计充值'},
                {align: 'center',fixed: 'right', toolbar: '#recharge-table-bar', title: '操作'}
            ]]
        });

        // 工具条点击事件:查看详情
        table.on('tool(recharge-table)', function (obj) {
            index.openNewTab({
                title:'充值详情',
                url:'pages/consume/rechargeDetails.html',
                // url:'pages/consume/rechargeDetails.html?player_id=' + obj.data.id,
                menuId: 'rechargeDetails'
            })
        });

        // 搜索按钮点击事件
        $('#recharge-btn-search').click(function () {
            var key = $('#recharge-search-key').val();
            var value = $('#recharge-search-value').val();
            table.reload('recharge-table', {where: {rechargeSearchKey: key, rechargeSearchValue: value}});
        });
    });
</script>